package com.yanqu.road.server.cmd.activity.deepfishing;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.DeepFishingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.deepseafishing.DeepFishingModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_DEEP_FISHING_UPGRADE_FISH_ROD_PART, desc = "深海觅诊开始游戏")
public class DeepFishingUpgradeRodPart extends AbstractCommand {
    private int activityId;
    private int upgradePartType;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DeepFishingProto.deepFishingUpgradeFishRodPartReqMsg msg = DeepFishingProto.deepFishingUpgradeFishRodPartReqMsg.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        upgradePartType = msg.getRodPartType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(DeepFishingModule.class).levelUpFishingRod(activityId,upgradePartType);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            DeepFishingProto.deepFishingUpgradeFishRodPartRespMsg.Builder builder = DeepFishingProto.deepFishingUpgradeFishRodPartRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DEEP_FISHING_UPGRADE_FISH_ROD_PART,builder);
        }
    }
}
